package cur.nature.starter.dao;

import cur.nature.framework.core.util.StringUtil;
import cur.nature.framework.mvc.crud.CrudDao;
import cur.nature.starter.model.Manager_DictVO;
import cur.nature.tinyorm.core.bean.PageBean;
import cur.nature.tinyorm.core.template.DefaultJdbcTemplate;
import mybatis.manager.entity.Manager_DictPO;
import mybatis.manager.entity.Manager_DictPOExample;
import mybatis.manager.mapper.Manager_DictPOMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 通用字典表 Dao
 * 作者：Auto Generator By wujian
 * 生成日期：2023-07-09 16:05:31
 */
@Component
@DependsOn(DefaultJdbcTemplate.TEMPLATE)
public class Manager_DictDao extends CrudDao<Manager_DictPO, Manager_DictVO> {
    public Manager_DictDao(@Qualifier(DefaultJdbcTemplate.TEMPLATE) DefaultJdbcTemplate template) {
        super( Manager_DictPO.class, Manager_DictVO.class, template);
    }

    @Autowired
    private Manager_DictPOMapper dictPOMapper;

    public PageBean<Manager_DictVO> list(Manager_DictVO.list_Param param) throws Exception {
        StringBuilder condition = new StringBuilder(" 1=1 ");
        if(StringUtil.isNotEmpty(param.getKeyword())){
            condition.append(" and a.code like '"+param.getKeyword()+"%' ");
        }
        String sql = "select * from admin_sys_dict a  where " + condition;
        PageBean<Manager_DictVO> list = queryForPage(sql, param.buildPage(),
                null, Manager_DictVO.class);
        return list;
    }

    public List<Manager_DictVO> listByCond(Manager_DictVO.list_Param param) throws Exception {
        StringBuilder condition = new StringBuilder(" 1=1 ");
        if(StringUtil.isNotEmpty(param.getKeyword())){
            condition.append(" and a.code like '"+param.getKeyword()+"%' ");
        }
        Manager_DictPOExample managerDictPOExample = new Manager_DictPOExample();
        List<Manager_DictPO> managerDictPOS = dictPOMapper.selectByExample(managerDictPOExample);
        return toVoList(managerDictPOS);
    }

}

